import axios from "axios";
import { message as antdMessage } from "antd";
export const request = axios.create({
  timeoutErrorMessage: "请求超时······",
  timeout: 10000,
});
request.interceptors.request.use(
  config => {
    if (config.headers) config.headers.token = localStorage.getItem("token");
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
request.interceptors.response.use(
  response => {
    const { code, message } = response.data;
    if (code === 403) {
      antdMessage.error(message);
    }
    return response;
  },
  error => {
    const { status } = error.response;
    if (status === 404) {
      antdMessage.error(`请求接口不存在,${error.message}`);
    }
    return Promise.reject(error);
  }
);
